<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>学生列表</title>

</head>
<body>

    <form action="/database">
        地址：<input type="text" name="key" value="{{$form['key']??''}}">


        @php
            $maleChecked = ($form['sex'] ?? '') == 'male' ? 'checked' : '';
            $femaleChecked = ($form['sex'] ?? '') == 'female' ? 'checked' : '';

        @endphp
        <input type="radio" name="sex" value="male" {{ $maleChecked }}>男
        <input type="radio" name="sex" value="female" {{ $femaleChecked }}>女
        <br>
        @foreach($majors as $major)
            <input type="radio" name="major" value="{{ $major??''}}">{{ $major??'' }}
        @endforeach
        <button type="submit">搜索</button>
    </form>

    <h1>学生列表</h1>
    <table class="table table-bordered" border="1">
        <thead>
        <tr>
            <th>ID</th>
            <th>名字</th>
            <th>姓</th>
            <th>性别</th>
            <th>出生日期</th>
            <th>电子邮件</th>
            <th>电话号码</th>
            <th>地址</th>
            <th>城市</th>
            <th>州/省</th>
            <th>主修专业</th>
            <th>平均绩点 (GPA)</th>
            <th>创建时间</th>
            <th>更新时间</th>
        </tr>
        </thead>
        <tbody>
        @foreach ($user as $student)
            @if($student->first_name!=="周" and $student->gpa>3.5)
            <tr>
                <td>{{ $student->id }}</td>
                <td>{{ $student->first_name }}</td>
                <td>{{ $student->last_name }}</td>
                <td>{{ $student->gender }}</td>
                @php
                    $birthday = new DateTime($student->birthday);
                    $isAfter2002 = $birthday > new DateTime('2002-01-01');
                @endphp
                @if($isAfter2002)
                    <td>{{ $student->birthday }}</td>
                @else
                    <td></td>
                @endif

                <td>{{ $student->email }}</td>
                <td>{{ $student->phone_number }}</td>
                <td>{{ $student->address }}</td>
                <td>{{ $student->city }}</td>
                <td>{{ $student->state }}</td>
                <td>{{ $student->major }}</td>
                <td>{{ $student->gpa }}</td>
                <td>{{ $student->created_at }}</td>
                <td>{{ $student->updated_at }}</td>
            </tr>
            @endif
        @endforeach
        </tbody>
    </table>

</body>
</html>
